from tkinter import *
import random

root = Tk()
root.title('画布')
root.geometry('200x200+200+200')

cv = Canvas(root,width=150,height=150,bg='red')
cv.pack()

# 画一条折线，由三个坐标组成
line = cv.create_line(10, 10, 22, 22, 40, 35)
# 画一个矩形
rect = cv.create_rectangle(50, 50, 100, 100)
# 画一个圆
oval = cv.create_oval(50, 50, 100, 100)
# 插入一张图片
photo = PhotoImage(file='1.gif')
cv.create_image(130, 130, image=photo)

# 练习，画很多矩形
def dreaw():
    w = cv['width']
    h = cv['height']
    for s in range(0,5):
        x1 = random.randrange(int(w)/2)
        y1 = random.randrange(int(h)/2)
        x2 = random.randrange(int(w)/2)
        y2 = random.randrange(int(h)/2)
        cv.create_rectangle(x1, y1, x2, y2)

bu = Button(root,text='画图',command=dreaw).pack()

root.mainloop()